//
//  UIWindow+Extension.swift
//  Lease_IOS
//
//  Created by Mr.wang on 2019/2/18.
//  Copyright © 2019 Mr.wang. All rights reserved.
//

import UIKit

extension UIWindow {
    
    func setRootViewController(_ controller: UIViewController,
                               animated: Bool = true,
                               type: CATransitionType = .fade) {
        if animated {
            let animation = CATransition()
            animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
            animation.type = type
            animation.duration = 0.3
            animation.subtype = CATransitionSubtype.fromRight
            UIApplication.shared.keyWindow?.layer.add(animation, forKey: nil)
        }
        UIApplication.shared.keyWindow?.rootViewController = controller
    }
    
}
